<?php
	if(!isset($_REQUEST['ajax'])){ $_REQUEST['ajax'] = "";}
	if($_REQUEST['ajax']!=true) include 'header.tpl.php';
	//include 'project_panel.tpl.php';
?>
	<div class="row">
		<div class="col-lg-12">
			<ul class="shortcut-buttons-set">
				<li>
					<a class="shortcut-button" href='#project_view/pid=<?php echo $this->item['pId'];?>'><span>
					<i class="aicon-task_detail"></i>
					<?php echo $this->language['detail'];?></span></a>
				</li>
				<?php if(check_permission('project_salary_edit')): ?>
				<li>
					<a class="shortcut-button" href='#project_view/pid=<?php echo $this->item['pId'];?>&mod=salaries'><span>
					<i class="aicon-chietkhau"></i>
					Hoa hồng</span></a>
				</li>
				<?php endif;?>
				<?php if(check_permission('project_view') && $this->item['pParent'] == 0){ ?>
				<li>
					<a class="shortcut-button" href='#project_view/pid=<?php echo $this->item['pId'];?>&mod=bussiness'><span>
					<i class="aicon-chart"></i>
					<?php echo $this->language['bussiness'];?></span></a>
				</li>
				<?php }?>
				<?php if($this->item['pParent'] == 0 && $this->item['pCreateUser']==$_SESSION['userId'] && $this->item['pStatus'] < 3):?>
				<li>
					<a class="shortcut-button" href='#project_create/pid=<?php echo $this->item['pId'];?>'><span>
					<i class="aicon-project_add"></i>
					Tạo dự án con</span></a>
				</li>
				<?php endif;?>
			</ul>
		</div>
	</div>
	<input type="hidden" id="pidhid" name="pidhid" value="<?php echo $this->item['pId'];?>">
	<div class="row">
		<div class="col-lg-4">
			<div class="panel">
				<div class="panel-heading">
					<div class="panel-title"><i class="aicon-task_detail"></i> <?php echo $this->language['detail'];?></div>
				</div>
				<div class="panel-body">
					<ul class="list-group">
						<?php if($this->item['pParent']):?>
						<li class="list-group-item">
							<b>Dự án Cha</b>
							<span class="pull-right"><a href="#project_view/pid=<?php echo $this->item['pParent'];?>"><?php echo $this->item['parentName'];?></a></span>
							<div class="clear"></div>
						</li>
						<?php endif;?>
						<li class="list-group-item">
							<b><?php echo $this->language['project_code'];?></b>
							<span class="pull-right"><?php echo $this->item['pCode'];?></span>
							<div class="clear"></div>
						</li>
						<li class="list-group-item">
							<b><?php echo $this->language['contract_code'];?></b>
							<span class="pull-right"><?php echo ($this->item['pContract']) ? $this->item['pContract'] : "Chưa có";?></span>
							<div class="clear"></div>
						</li>
						<li class="list-group-item">
							<b><?php echo $this->language['creator'];?></b>
							<span class="pull-right"><?php echo $_SESSION['user_data'][$this->item['pCreateUser']]['fullname'];?></span>
							<div class="clear"></div>
						</li>
						<li class="list-group-item">
							<b><?php echo $this->language['project_create_date'];?></b>
							<span class="pull-right"><?php echo date("d/m/Y",$this->item['pCreateTime']);?></span>
							<div class="clear"></div>
						</li>
						<li class="list-group-item">
							<b><?php echo $this->language['project_start_date'];?></b>
							<span class="pull-right"><?php echo date("d/m/Y",$this->item['pStartTime']);?></span>
							<div class="clear"></div>
						</li>
						<li class="list-group-item">
							<b><?php echo $this->language['project_end_date'];?></b>
							<span class="pull-right"><?php echo date("d/m/Y",$this->item['pDeadTime']);?></span>
							<div class="clear"></div>
						</li>
						<li class="list-group-item">
							<b><?php echo $this->language['project_accept_date'];?></b>
							<span class="pull-right"><?php echo ($this->item['pAcceptTime']>0) ? date("d/m/Y",$this->item['pAcceptTime']) : "Chưa chấp nhận";?></span>
							<div class="clear"></div>
						</li>
						<li class="list-group-item">
							<b><?php echo $this->language['project_priority'];?></b>
							<span class="pull-right">
								<?php
									if($this->item['pPriority']==1) echo "Thấp";
									elseif($this->item['pPriority']==2) echo "Bình thường";
									elseif($this->item['pPriority']==3) echo "Cao";
									else echo "Không biết";
								?>
							</span>
							<div class="clear"></div>
						</li>
						<li class="list-group-item">
							<b><?php echo $this->language['attach_file'];?></b>
							<span class="pull-right">
								<?php
									if($this->item['pFile1']!=""){
										$f1 = explode(";",$this->item['pFile1']);
										echo "<ul>";
										foreach($f1 as $file){
											echo "<li><a href='download.php?file=".$file."'>$file</a></li>";
										}
										echo "</ul>";
									}
									else echo "Không có";
								?>
							</span>
							<div class="clear"></div>
						</li>
						<li class="list-group-item">
							<b><?php echo $this->language['last_activity'];?></b>
							<span class="pull-right"><?php echo $this->item['pLastActivityDesc']." - ".date("d/m/Y",$this->item['pLastActivity']); ?></span>
							<div class="clear"></div>
						</li>
						<li class="list-group-item">
							<b><?php echo $this->language['receiver'];?></b>
							<span class="pull-right"><?php echo $this->receiver;?></span>
							<div class="clear"></div>
						</li>
						<li class="list-group-item">
							<b>Khách hàng</b>
							<span class="pull-right">
								<?php if(count($this->viewers) > 0):?>
								<ul>
									<?php foreach($this->viewers as $viewer):?>
									<li><?php echo $viewer['cust_sex'].$viewer['cust_last_name'];?></li>
									<?php endforeach;?>
								</ul>
								<?php else:?>
								Chưa cập nhật
								<?php endif;?>
							</span>
							<div class="clear"></div>
						</li>
						<li class="list-group-item">
							<b><?php echo $this->language['complete_file'];?></b>
							<span class="pull-right">
								<?php
									if($this->item['pFile2']!=""){
										$f2 = explode(";",$this->item['pFile2']);
										echo "<ul>";
										foreach($f2 as $file){
											echo "<li><a href='download.php?file=".$file."'>$file</a></li>";
										}
										echo "</ul>";
									}
									else echo "Không có";
								?>
							</span>
							<div class="clear"></div>
						</li>
						<li class="list-group-item">
							<b><?php echo $this->language['status'];?></b>
							<span class="pull-right">
								<?php
									if($this->item['pStatus']==0) echo "<span class='label label-waiting'>".$this->language['waiting']."</span>";
									elseif($this->item['pStatus']==1) echo "<span class='label label-process'>".$this->language['processing']."</span>";
									elseif($this->item['pStatus']==2) echo "<span class='label label-preview'>".$this->language['testing']."</span>";
									elseif($this->item['pStatus']==3 || $this->item['pStatus'] == 4) echo "<span class='label label-complete'>".$this->language['completed']."</span>";
									elseif($this->item['pStatus']==-1) echo "<span class='label label-deny'>".$this->language['cancelled']."</span>";
									else echo $this->language['unknown'];
								?>
							</span>
							<div class="clear"></div>
						</li>
					</ul>
					<?php if(isset($this->displayBtn)) echo "<div class='form-group text-center'>".$this->displayBtn."</div>";?>
					<form action="javascript:;" class="form-horizontal">
					<?php if($this->item['pCreateUser']==$_SESSION['userId'] && $this->item['pStatus']==2): ?>
						<div class="form-group text-center">
							<a href="javascript:;" class="btn btn-primary" onClick="acpDuan();" id="acpDuan"><?php echo $this->language['accept'];?></a>
							<a href="javascript:;" class="btn btn-deny" onClick="dnyDuan();" id="dnyUpdate"><?php echo $this->language['cancelled'];?></a>
						</div>
					<?php endif; ?>
					</form>
				</div>
			</div>
			<?php if(check_permission('project_edit') || isset($this->isCreator)){ ?>
			<div class="panel">
				<div class="panel-heading">
					<div class="panel-title"><i class="aicon-network"></i> <?php echo $this->language['project_functions'];?></div>
				</div>
				<div class="panel-body">
					<form action="javascript:themGiahan();">
						<div class="form-group">
							<label><?php echo $this->language['project_add_employee'];?></label>
							<select name="mRecei[]" id="mRecei" class="form-control" style="height:150px;" multiple>
								<?php echo $this->selectRecei;?>
							</select>
						</div>
						<div class="form-group">
							<label><?php echo $this->language['project_start_date'];?></label>
							<input type="text" class="form-control" name="projectStart" id="datepicker1" value="<?php echo date("d-m-Y",$this->item['pStartTime']);?>" />
						</div>
						<div class="form-group">
							<label><?php echo $this->language['project_end_date'];?></label>
							<input type="text" class="form-control" name="projectDead" id="datepicker" value="<?php echo date("d-m-Y",$this->item['pDeadTime']);?>" />
						</div>
						<div class="form-group text-center">
							<button class="btn btn-primary" type="submit"><?php echo $this->language['accept'];?></button>
						</div>
					</form>
					<?php if($this->item['pContract'] == ''){ ?>
					<form action="javascript:updateContract();">
						<div class="form-group">
							<label><?php echo $this->language['contract_code'];?></label>
							<input type="text" class="form-control" id="contract_code" name="contract_code" />
						</div>
						<div class="form-group">
							<button class="btn btn-primary" type="submit"><?php echo $this->language['accept'];?></button>
						</div>
					</form>
					<?php } ?>
					<script type="text/javascript" src="resources/scripts/jquery-ui.min.js"></script>
					<script type="text/javascript" src="resources/scripts/jquery.datePicker.js"></script>
					<script>
					$(function() {
						$( "#datepicker1" ).datepicker({dateFormat: 'dd-mm-yy'});
						$( "#datepicker" ).datepicker({dateFormat: 'dd-mm-yy'});
					});
					</script>
				</div>
			</div>
			<?php } ?>
			<?php if(check_permission('project_edit')):?>
			<div class="panel">
				<div class="panel-heading">
					<div class="panel-title"><i class="aicon-social"></i> Thêm khách hàng</div>
				</div>
				<div class="panel-body">
					<form action="javascript:project_cust();" id="project_cust">
						<div class="form-group">
							<label class="control-label">Chọn khách hàng</label>
							<select name="customer[]" multiple size=5 class="form-control">
								<?php foreach($this->customers as $cust):?>
								<option value="<?php echo $cust['cust_id'];?>"><?php echo $cust['cust_sex'].' '.$cust['cust_first_name'].' '.$cust['cust_last_name'];?></option>
								<?php endforeach;?>
							</select>
						</div>
						<div class="form-group">
							<input type="hidden" name="mod" value="project_cust">
							<input type="hidden" name="pid" value="<?php echo $this->item['pId'];?>">
							<button class="btn btn-primary" type="submit"><?php echo $this->language['accept'];?></button>
						</div>
					</form>
				</div>
			</div>
			<?php endif;?>
			<?php if(isset($this->isLeader) && $this->item['pStatus'] == 1){ ?>
			<div class="panel">
				<div class="panel-heading">
					<div class="panel-title"><i class="aicon-social"></i> <?php echo $this->language['project_update'];?></div>
				</div>
				<div class="panel-body">
					<form action="javascript:updateDuan();" class="form-horizontal">
						<div class="form-group">
							<label class="col-lg-4 control-label"><?php echo $this->language['status'];?></label>
							<div class="col-lg-8">
								<div class="input-group">
									<input type="text" class="form-control" name="percent" id="percent" value="<?php echo $this->item['pPercent'];?>" />
									<span class="input-group-addon">%</span>
								</div>
							</div>
						</div>
						<div class="form-group">
							<div class="col-lg-offset-4 col-lg-8"><button class="col-offset-4 btn btn-warning" type="submit"><?php echo $this->language['update'];?></button></div>
						</div>
					</form>
				</div>
			</div>
			<div class="panel">
				<div class="panel-heading">
					<div class="panel-title"><i class="aicon-social"></i> Hoàn thành dự án</div>
				</div>
				<div class="panel-body">
					<form action="javascript:submitDuan();" class="form-horizontal">
						<div class="form-group">
							<label class="col-lg-4 control-label"><?php echo $this->language['attach_file'];?></label>
							<div class="col-lg-8">
								<div id="file-uploader"></div>
								<input type=hidden id="uploadfile" name="uploadfile" value="">
								<div id="uploaded"></div>
							</div>
						</div>
						<div class="form-group">
							<div class="col-lg-offset-4 col-lg-8"><button class="col-offset-4 btn btn-primary" type="submit"><?php echo $this->language['completed'];?></button></div>
						</div>
					</form>
				</div>
			</div>
			<?php } ?>
		</div>
		<div class="col-lg-8">
			<div class="panel">
				<div class="panel-heading">
					<div class="panel-title"><i class="aicon-task_content"></i> <?php echo $this->language['project_content'];?></div>
				</div>
				<div class="panel-body">
					<form action="javascript:;" onSubmit="return false;">
						<div class="form-group">
							<label><?php echo $this->language['project_name'];?> : <font color=red id="change_pname"><?php echo $this->item['pName'];?></font></label>
							<?php if($this->item['pCreateUser']==$_SESSION['userId'] && $this->item['pStatus']<2){ ?>
							<textarea class="wysiwyg form-control" rows=10 id="textarea" name="projectContent"><?php echo $this->item['pContent']; ?></textarea>
							<?php }else{ echo "<hr><p>".$this->item['pContent']."</p>"; } ?>
						</div>
						<?php if($this->item['pCreateUser']==$_SESSION['userId']){
							if($this->item['pStatus']<2){ ?>
						<div class="form-group">
							<button class="btn btn-warning" onClick="editDuan();" id="pUpdate"><?php echo $this->language['update'];?></button>
						</div>
						<?php } } ?>
					</form>
				</div>
			</div>
			<?php if(count($this->item['sub_projects'])>0):?>
			<div class="panel">
				<div class="panel-heading">
					<div class="panel-title"><i class="aicon-network"></i> Dự án con</div>
				</div>
				<div class="panel-body">
					<table class="table table-hover">
						<thead>
							<tr>
								<th>Tên dự án</th>
								<th width="110px">Tình trạng</th>
							</tr>
						</thead>
						<tbody>
							<?php foreach($this->item['sub_projects'] as $row):?>
							<tr>
								<td><a href='#project_view/pid=<?php echo $row['pId'];?>'><?php echo $row['pName'];?></a></td>
								<td><?php
									if($row['pStatus']==0) echo "<span class='label label-waiting'>".$this->language['waiting']."</span>";
									elseif($row['pStatus']==1) echo "<span class='label label-process'>".$this->language['processing']."</span>";
									elseif($row['pStatus']==2) echo "<span class='label label-preview'>".$this->language['testing']."</span>";
									elseif($row['pStatus']==3 || $row['pStatus'] == 4) echo "<span class='label label-complete'>".$this->language['completed']."</span>";
									elseif($row['pStatus']==-1) echo "<span class='label label-deny'>".$this->language['cancelled']."</span>";
									else echo $this->language['unknown'];
									?>
								</td>
							</tr>
							<?php endforeach;?>
						</tbody>
					</table>
				</div>
			</div>
			<?php endif;?>
			<p>
				<?php if($this->item['pParent'] == 0 && $this->item['pCreateUser']==$_SESSION['userId'] && $this->item['pStatus'] < 3):?>
				<a href="#project_create/pid=<?php echo $this->item['pId'];?>" class="btn btn-black"><i class="aicon-plus"></i> Tạo dự án con</a>
				<?php endif;?>
				<?php if($this->item['pStatus'] < 3):?>
				<a href="#task_create&pid=<?php echo $this->item['pId'];?>" class="btn btn-primary"><i class="aicon-plus"></i> Tạo công việc mới</a>
				<?php endif;?>
			</p>
			<?php if(isset($this->hvTask) || count($this->item['sub_projects'])>0): ?>
			<iframe id="project_gantt" frameborder="0" scrolling="no" src="./ttg/report/views/panel.html?id=33&project_id=<?php echo $this->item['pId'];?>&frame"></iframe>
			<?php else: ?>
			<div class="panel">
				<div class="panel-heading">
					<div class="panel-title"><i class="aicon-calendar"></i> Lịch làm việc</div>
				</div>
				<div class="panel-body">
					<div class="alert alert-warning">Chưa có lịch làm việc</div>
				</div>
			</div>
			<?php endif; ?>
		</div>
	</div>
	<link href="resources/css/fileuploader.css" type="text/css" rel="stylesheet" />
	<script type="text/javascript" src="resources/scripts/jquery.wysiwyg.js"></script>
	<script type="text/javascript" src="resources/scripts/fileuploader.js"></script>
	<script type="text/javascript" src="resources/scripts/bootstrap-editable.js"></script>
	<script>
	$(".wysiwyg").wysiwyg();
	<?php if(isset($this->isLeader) && $this->item['pStatus'] == 1){ ?>
	var uploader = new qq.FileUploader({
		element: document.getElementById('file-uploader'),
		action: 'file.php?act=upload',
		debug: false
	});
	<?php } ?>
		$("#project_gantt").ready(function(){
			setTimeout(function(){
				var ih = $("#project_gantt").contents().height();
				$("#project_gantt").attr('height',ih);},2000);
		});
		$("#project_gantt").load(function(){
			setTimeout(function(){
			var ih = $("#project_gantt").contents().height();
			$(this).attr('height',ih);},2000);
		});
		$("#change_pname").editable({
			mode: 'inline',
			name: 'pname',
			pk: 1,
			params: {
				pid:$("#pidhid").val(),
				mod:'update_pname'
			},
			url: '?func=project_ajax&ajax=true',
			success: function(response,newValue){
				var getData = $.parseJSON($.trim(response));
				if(getData.type == 'error'){
					return getData.msg;
				}
			}
		});
	</script>
	<?php /*if(isset($this->hvTask)){?>
		<script type="text/javascript" src="resources/scripts/jquery.gantt.min.js"></script>
		<script type="text/javascript">
			$(function() {
				$(".gantt").gantt({
					source: [
						<?php for($i = 0;$i < count($this->task);$i++){?>
						{
							name: "<?php echo htmlspecialchars($this->task[$i]['uFullname'],ENT_QUOTES);?>",
							desc: "",
							values: [{
								from: "/Date(<?php echo $this->task[$i]['tStartTime']*1000;?>)/",
								to: "/Date(<?php echo $this->task[$i]['tDeadTime']*1000;?>)/",
								label: "<?php echo htmlspecialchars($this->task[$i]['tTitle'],ENT_QUOTES);?>",
								customClass: "<?php
									if($this->task[$i]['tStatus'] == 0) echo "ganttRed";
									elseif($this->task[$i]['tStatus'] == -1) echo "ganttGray";
									elseif($this->task[$i]['tStatus'] == 1) echo "ganttOrange";
									elseif($this->task[$i]['tStatus'] == 2) echo "ganttGreen";
									elseif($this->task[$i]['tStatus'] == 3) echo "ganttBlue";
									else echo "ganttGray";
									?>",
								dataObj: {id:<?php echo $this->task[$i]['tId'];?>}
							}]
						}<?php echo ($i < count($this->task)) ? ",":"";?>
						<?php } ?>
					],
					navigate: "scroll",
					scale: "days",
					maxScale: "months",
					minScale: "days",
					itemsPerPage: 15,
					months:["Tháng 1", "Tháng 2", "Tháng 3", "Tháng 4", "Tháng 5", "Tháng 6", "Tháng 7", "Tháng 8", "Tháng 9", "Tháng 10", "Tháng 11", "Tháng 12"],
					dow:["C", "H", "B", "T", "N", "S", "B"],
					waitText:"Loading....",
					onItemClick: function(data) {
						window.location.hash = 'task_view/tid='+data.id;
						e.preventDefault();
					}
				});
			});
		</script>
	<?php }*/ ?>
<?php if(isset($this->breadcrumb) && isset($this->title_header)):?>
	<script type="text/javascript">
		$(function() {
			$("#title-header").text('<?php echo $this->title_header;?>');
			$("#breadcrumb").html('<?php echo build_breadcrumb($this->breadcrumb);?>');
		});
	</script>
<?php endif;?>
<?php
	if($_REQUEST['ajax']!=true) include 'footer.tpl.php';
?>